package com.hxut.servlet;

import com.hxut.dao.GoodsDao;
import com.hxut.model.Goods;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

@WebServlet(name = "GoodListServlet",urlPatterns = "/goodListServlet")
public class GoodListServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //查询所有的产品信息
        ArrayList<Goods> goodsList = new ArrayList<Goods>();
        GoodsDao dao = new GoodsDao();
        goodsList = dao.findAllGoods();
        req.setAttribute("goodsList",goodsList);

        RequestDispatcher requestDispatcher = req.getRequestDispatcher("/good-list.jsp");
        requestDispatcher.forward(req,resp);
    }


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }


}
